package IntroScene;

import javax.swing.*;
import java.awt.*;

public class IntroPanel extends JPanel {
    public PicPanel picPanel = new PicPanel();
    int gapY = 0;
    int gapYY = 0;
    Timer timer;
    int i  =145;
    int flag = 0;
    int m =2;
    int[] x  = new int[289];
    int[] y = new int[300];
    int gap = 30;
    int gapX = 30;
    int flagY = 0;
    int flagX = 0;
    Go go = new Go();
    int sign = 0;

    Scene scene = new Scene();
    Thread my;
    public IntroPanel() {
         my = new Thread(()->{

            try {
                while(true){
                    go.changeImage();
                    Thread.sleep(10);
                    repaint();
                }

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        setLayout(null);
        add(picPanel);
        picPanel.setLocation(0, 0);
        for (int j = 0; j < 130; j++) {

            if (200 + gap >= 850) {
                gap = 30;
            }
            x[j] = 200 + gap;
            gap += 50;
        }
        for (int j = 0; j < 130; j++) {

            if (j % 13 == 0) {
                gapY += 50;
            }
            y[j] = 100 + gapY;

        }

        for (int j = 130; j < 289; j++) {

            if (1100 + gapX >= 1750) {
                gapX = 30;
            }
            x[j] = 1100 + gapX;
            gapX += 50;
        }
        for (int j = 130; j < 289; j++) {

            if (j % 13 == 0) {
                gapYY += 50;
            }
            y[j] = 100 + gapYY;

        }
    }


    public void reSize(JFrame frame){
        frame.setSize(2048,1024);
    }
    public void paint(Graphics g){
        super.paint(g);
        //g.drawImage(scene.map.get("book"),-20,-1050,null);(j*35)%2800-2000

        g.drawImage(scene.map.get("w"),200,200,null);
        for (int j = 1; j < m; j++) {
            g.drawImage(scene.map.get("" + j), x[j-1], y[j-1], null);
        }
        if(sign == 1)
        g.drawImage(go.img,1700,800,null);


        if(flag==0) {
            flag = 1;
            timer = new Timer(10, e -> {
                if(m==289){
                    timer.stop();
                    my.start();
                    sign = 1;
                }
                m+=1;
                repaint();
            });
            timer.start();
        }
    }
}
